import requests
from requests.auth import HTTPBasicAuth

# url = "http://127.0.0.1:8000/admin"


# print(response.status_code)
# print(response.headers.get("Location"))
# print(response.text)
#
# location = response.headers.get("Location")
# location = f'http://127.0.0.1:8000{location}'
# response = requests.get(location)
# print(response.status_code)

url = "http://127.0.0.1:8000/admin"

header = {
    'cookie':'sessionid=mpp9aqqkcx1umc1nkw38hvi0qtyala08'
}
cookie = {
    # 'sessionid':'hzx17ygyw2fqvtqe8grjvrsercoc4vcm'
}
response = requests.get(url,headers=header,cookies=cookie,allow_redirects=True)
print(response.status_code)
print(response.text)
if 'login' in response.url or '登录' in response.text.lower():
    print("SessionID 无效或已过期")
else:
    print("访问成功")


# url = "http://127.0.0.1:8000/admin"
#
# headers = {
#     # 'cookie': 'sessionid=hzx17ygyw2fqvtqe8grjvrsercoc4vcm'
# }
# cookie = {
#     # 'sessionid':'hzx17ygyw2fqvtqe8grjvrsercoc4vcm'
# }
# response = requests.get(url,headers=headers,cookies=cookie,auth=HTTPBasicAuth('fyx', '123456'))
# print(response.status_code)
# print(response.text)
# if 'login' in response.url or '登录' in response.text.lower():
#     print("SessionID 无效或已过期")
# else:
#     print("访问成功")

